package com.abysscore.yachtdesign;

import java.awt.Color;

import com.abysscore.yachtdesign.delphi.DelphiTools;

public class TFreeProjectSettings {

	private TFreeShip FOwner;
	private boolean FMainparticularsHasBeenset;     // Flag to check if the main particulars have been set before hydrostatic calculationss are being performed
	private boolean FDisableModelCheck;     // Disable the automatic checking of the surface
	private double FProjectAppendageCoefficient;
	private double FProjectBeam;
	private double FProjectDraft;
	private double FProjectLength;
	private double FProjectWaterDensity;
	private double FProjectMainframeLocation;
	private boolean FUseDefaultMainframeLocation;     // If set to true, the mainframe location is set to 0.5*project length, if false then value in FProjectMainframeLocation is used
	private String FProjectName;
	private String FProjectDesigner;
	private String FProjectComment;
	private String FProjectFileCreatedBy;
	private boolean FProjectShadeUnderwaterShip;
	private boolean FSavePreview;
	private Color FProjectUnderWaterColor;
	private TFreeUnitType FProjectUnits;
	private boolean FProjectSimplifyIntersections;
	private TFreeHydrostaticCoeff FFreeHydrostaticCoefficients;
               // General hydrostatics calculation settings
	private double FStartDraft;
	private double FEndDraft;
	private double FDraftStep;
	private double FTrim;
               // crosscurves settings
	private double[] FDisplacements;
	private int FNoDisplacements;
	private double FMinimumDisplacement;
	private double FMaximumDisplacement;
	private double FDisplIncrement;
	private boolean FUseDisplIncrements;
	private int FNoAngles;
	private double[] FAngles;
	private int FNoStabTrims;
	private double[] FStabTrims;
	private boolean FFreeTrim;
	private double FVCG;

	
	private void FSetFreeHydrostaticCoefficients(TFreeHydrostaticCoeff val) {
		FFreeHydrostaticCoefficients = val;
	}
	private void FSetDisableModelCheck(boolean Val) {
		FDisableModelCheck = Val;
	}
	private double  FGetProjectMainframeLocation() {
		return FProjectMainframeLocation;
	}
	private void FSetProjectAppendageCoefficient(double Val) {
		FProjectAppendageCoefficient = Val;
	}
	private void FSetProjectBeam(double Val) {
		FProjectBeam = Val;
	}
	private void FSetProjectComment(String Val) {
		FProjectComment = Val;
	}
	private void FSetProjectDraft(double Val) {
		FProjectDraft = Val;
	}
	private void FSetProjectFileCreatedBy(String Val) {
		FProjectFileCreatedBy = Val;
	}
	private void FSetProjectLength(double Val) {
		FProjectLength = Val;
	}
	private void FSetProjectMainframeLocation(double val) {
		FProjectMainframeLocation = val;
	}
	private void FSetProjectName(String Val) {
		FProjectName = Val;
	}
	private void FSetProjectDesigner(String Val) {
		FProjectDesigner = Val;
	}
	private void FSetProjectShadeUnderwaterShip(boolean Val) {
		FProjectShadeUnderwaterShip = Val;
	}
	private void FSetProjectSimplifyIntersections(boolean val) {
		FProjectSimplifyIntersections = val;
	}
	private void FSetProjectUnderWaterColor(Color Val) {
		FProjectUnderWaterColor = Val;
	}
	private void FSetProjectUnits(TFreeUnitType Val) {
		FProjectUnits = Val;
	}
	private void FSetProjectWaterDensity(double Val) {
		FProjectWaterDensity = Val;
	}
	private void FSetSavePreview(boolean val) {
		FSavePreview =val;
	}
	private void FSetStartDraft(double Val) {
		FStartDraft = Val;
	}
	private void FSetEndDraft(double Val) {
		FEndDraft = Val;
	}
	private void FSetDraftStep(double Val) {
		FDraftStep = Val;
	}
	private void FSetTrim(double Val) {
		FTrim = Val;
	}
	private void FSetUseDefaultMainframeLocation(boolean Val) {
		FUseDefaultMainframeLocation = Val;
	}
	
	
	public void Clear() {
	}
	public TFreeProjectSettings(TFreeShip Owner) {
		FOwner = Owner;
	}
	public void Edit() {
	}                              // User input of mainparticulars and project setting
	public void LoadBinary(TFreeFileBuffer Source, TJPegImage Image) {
		int I = 0;
		TJPegImage Jpg;

		Clear();
		Source.Load(FProjectName);
		Source.Load(FProjectDesigner);
		Source.Load(FProjectLength);
		Source.Load(FProjectBeam);
		Source.Load(FProjectDraft);
		Source.Load(FMainparticularsHasBeenset);
		Source.Load(FProjectWaterDensity);
		Source.Load(FProjectAppendageCoefficient);
		Source.Load(FProjectShadeUnderwaterShip);
		Source.Load(FProjectUnderWaterColor);
		Source.Load(I);
		FProjectUnits = TFreeUnitType.values()[I];
		Source.Load(FUseDefaultMainframeLocation);
		Source.Load(FProjectMainframeLocation);
		Source.Load(FDisableModelCheck);
		Source.Load(FProjectComment);
		Source.Load(FProjectFileCreatedBy);
		FSavePreview = true;
		if (FOwner.FileVersion().compareTo(TFreeFileVersion.fv210) > 0)
		{
			Source.Load(I);
			FFreeHydrostaticCoefficients = TFreeHydrostaticCoeff.values()[I];
			Source.Load(FSavePreview);
			if (FSavePreview)
			{
				Jpg= new TJPegImage();
				Source.Load(Jpg);
				if (Image != null)
					Image = Jpg;
			}
			if (FOwner.FileVersion().compareTo(TFreeFileVersion.fv230) > 0)
			{
				Source.Load(FProjectSimplifyIntersections);
			}
			if (FOwner.FileVersion().compareTo(TFreeFileVersion.fv250) > 0)
			{         // hydrostatics
				Source.Load(FStartDraft);
				Source.Load(FEndDraft);
				Source.Load(FDraftStep);
				Source.Load(FTrim);
				// Crosscurves settings
				Source.Load(FNoDisplacements);
				DelphiTools.SetLength(FDisplacements,FNoDisplacements);
				for (I=1; I <= FNoDisplacements; I++)
					Source.Load(FDisplacements[I-1]);
				Source.Load(FMinimumDisplacement);
				Source.Load(FMaximumDisplacement);
				Source.Load(FDisplIncrement);
				Source.Load(FUseDisplIncrements);
				Source.Load(FNoAngles);
				DelphiTools.SetLength(FAngles,FNoAngles);
				for (I=1; I<=FNoAngles; I++)
					Source.Load(FAngles[I-1]);
				Source.Load(FNoStabTrims);
				DelphiTools.SetLength(FStabTrims,FNoStabTrims);
				for (I=1; I<= FNoStabTrims; I++)
					Source.Load(FStabTrims[I-1]);
				Source.Load(FFreeTrim);
				Source.Load(FVCG);
			}
		}
	}
	public void SaveBinary(TFreeFileBuffer Destination) {
	}
	
	
	public boolean DisableModelCheck() { return FDisableModelCheck; }
	public void DisableModelCheck(boolean val) { FSetDisableModelCheck(val); }
	public double Hydrostatics_Startdraft() { return FStartDraft; }
	public void Hydrostatics_Startdraft(double val) { FSetStartDraft(val); }
	public double Hydrostatics_EndDraft() { return FEndDraft; }
	public void Hydrostatics_EndDraft(double val) { FSetEndDraft(val); }
	public double Hydrostatics_DraftStep() { return FDraftStep; }
	public void Hydrostatics_DraftStep(double val) { FSetDraftStep(val); }
	public double Hydrostatics_Trim() { return FTrim; }
	public void Hydrostatics_Trim(double val) { FSetTrim(val); }
	public boolean MainparticularsHasBeenset() { return FMainparticularsHasBeenset; }
	public TFreeShip Owner() { return FOwner; }
	public void Owner(TFreeShip val) { FOwner = val; }
	public double ProjectAppendageCoefficient() { return FProjectAppendageCoefficient; }
	public void ProjectAppendageCoefficient(double val) { FSetProjectAppendageCoefficient(val); }
	public double ProjectBeam() { return FProjectBeam; }
	public void ProjectBeam(double val) { FSetProjectBeam(val); }
	public TFreeHydrostaticCoeff ProjectCoefficients() { return FFreeHydrostaticCoefficients; }
	public void ProjectCoefficients(TFreeHydrostaticCoeff val) { FSetFreeHydrostaticCoefficients(val); }
	public String ProjectComment() { return FProjectComment; }
	public void ProjectComment(String val) { FSetProjectComment(val); }
	public double ProjectDraft() { return FProjectDraft; }
	public void ProjectDraft(double val) { FSetProjectDraft(val); }
	public String ProjectFileCreatedBy() { return FProjectFileCreatedBy; }
	public void ProjectFileCreatedBy(String val) { FSetProjectFileCreatedBy(val); }
	public double ProjectLength() { return FProjectLength; }
	public void ProjectLength(double val) { FSetProjectLength(val); }
	public double ProjectMainframeLocation() { return FGetProjectMainframeLocation(); }
	public void ProjectMainframeLocation(double val) { FSetProjectMainframeLocation(val); }
	public String ProjectName() { return FProjectName; }
	public void ProjectName(String val) { FSetProjectName(val); }
	public String ProjectDesigner() { return FProjectDesigner; }
	public void ProjectDesigner(String val) { FSetProjectDesigner(val); }
	public boolean ProjectShadeUnderwaterShip() { return FProjectShadeUnderwaterShip; }
	public void ProjectShadeUnderwaterShip(boolean val) { FSetProjectShadeUnderwaterShip(val); }
	public boolean ProjectSimplifyIntersections() { return FProjectSimplifyIntersections; }
	public void ProjectSimplifyIntersections(boolean val) { FSetProjectSimplifyIntersections(val); }
	public Color ProjectUnderWaterColor() { return FProjectUnderWaterColor; }
	public void ProjectUnderWaterColor(Color val) { FSetProjectUnderWaterColor(val); }
	public TFreeUnitType ProjectUnits() { return FProjectUnits; }
	public void ProjectUnits(TFreeUnitType val) { FSetProjectUnits(val); }
	public double ProjectWaterDensity() { return FProjectWaterDensity; }
	public void ProjectWaterDensity(double val) { FSetProjectWaterDensity(val); }
	public boolean SavePreview() { return FSavePreview; }
	public void SavePreview(boolean val) { FSetSavePreview(val); }
	public boolean UseDefaultMainframeLocation() { return FUseDefaultMainframeLocation; }
	public void UseDefaultMainframeLocation(boolean val) { FSetUseDefaultMainframeLocation(val); }
}
